<template>
  <div class="home-header">
    <el-row class="row_header">
      <!-- 左边 -->
      <el-col :span="10" class="left">
        <div class="header-img" @click="$router.push('/home/personalrc')">
        </div>
        <div class="header-arrow">
          <i class="arrow arrow-left" @click="$router.back()"></i>
          <i class="arrow arrow-right" @click="$router.forward()"></i>
        </div>
        <div class="header-search">
          <el-input placeholder="输入搜索的音乐" suffix-icon="el-icon-search" v-model="key" @keyup.enter.native="searchKey"></el-input>
        </div>
      </el-col>
      <!-- 右边 -->
      <el-col :span="14" class="right">
        <div class="switch-group">
          <el-switch v-model="switchValue1" inactive-text="侧边栏">
          </el-switch>
          <el-switch v-model="switchValue2" inactive-text="音乐栏">
          </el-switch>
          <el-switch v-model="switchValue3" inactive-text="mini音乐栏">
          </el-switch>
        </div>
        <div class="login">
          <a href="/login" class="login_a"><i class="el-icon-user" v-show="!userInfo.profile.avatarUrl"></i>
            <img v-lazy="userInfo.profile.avatarUrl">
            {{nickName}}</a>
        </div>
        <div class="icon">
          <a href="javascript:;">
            <i class="iconfont icon-gitee"></i>
          </a>
          <a href="javascript:;">
            <i class="iconfont icon-github"></i>
          </a>
        </div>
        <!-- 下拉菜单 -->
        <el-dropdown>
          <span class="select_down">下拉菜单<i class="iconfont icon-xiajiantou"></i></span>
          <el-dropdown-menu slot="dropdown">
            <!-- 一级下拉菜单 -->
            <el-dropdown-item>
              <!-- 二级下拉菜单 -->
              <el-dropdown>
                <span>项目代码部署地址<i class="iconfont icon-xiajiantou"></i></span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>
                    <a href="javascript:;">Gitee仓库地址<i class="iconfont icon-xiajiantou"></i></a>
                  </el-dropdown-item>

                  <el-dropdown-item><a href="javascript:;">GitHub仓库地址<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>

                  <el-dropdown-item><a href="javascript:;">CSDN博客地址<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-dropdown-item>

            <el-dropdown-item>
              <!-- 二级下拉菜单 -->
              <el-dropdown>
                <span>项目部署站点<i class="iconfont icon-xiajiantou"></i></span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>
                    <a href="javascript:;">Vue_shop后台管理项目<i class="iconfont icon-xiajiantou"></i></a>
                  </el-dropdown-item>

                  <el-dropdown-item><a href="javascript:;">仿饿了么外卖项目<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>

                  <el-dropdown-item><a href="javascript:;">网易云项目<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-dropdown-item>

            <el-dropdown-item>
              <!-- 二级下拉菜单 -->
              <el-dropdown>
                <span>项目相关推荐<i class="iconfont icon-xiajiantou"></i></span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>
                    <a href="https://neteasecloudmusicapi.vercel.app">API地址参考文档<i class="iconfont icon-xiajiantou"></i></a>
                  </el-dropdown-item>

                  <el-dropdown-item><a href="https://www.bilibili.com/video/BV1RE411W776?p=1">B站教程API网络请求参考<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>

                  <el-dropdown-item><a href="https://aplayer.netlify.app/docs/">APlayer播放器插件<i class="iconfont icon-xiajiantou"></i></a></el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'HomeHeader',
  data() {
    return {
      switchValue1: true,
      switchValue2: true,
      switchValue3: false,
      // 搜索框输入值
      key: ''
    }
  },
  methods: {
    searchKey() {
      if (this.key.trim === '') {
        this.$message({
          message: '搜索内容不能为空',
          type: 'warning'
        })
      }
      if (this.$route.name !== 'searchIndex') {
        this.$router.push(`/home/searchIndex/${this.key}`)
      }
      this.$bus.$emit('searchClick', this.key)
    }
  },
  computed: {
    ...mapState(['userInfo']),
    nickName() {
      return this.userInfo.profile.nickname ? this.userInfo.profile.nickname : '登录/注册'
    }
  }
}
</script>

<style lang="less" scoped>
.home-header {
  width: 100%;
  height: 100%;
  max-width: 1536px;
  min-height: 49px;
  box-sizing: border-box;
  padding: 0 70px 0 15px;
  border-bottom: 2px solid red;
  background: hotpink;
  color: #fff !important;
  .el-row {
    width: 100%;
    height: 100%;
    .el-col-10 {
      display: flex;
      align-items: center;

      .header-img {
        width: 160px;
        height: 40px;
        background: url('../../assets/topbar.png');
        background-position: 0 -15px;
        margin-right: 20px;
        display: flex;
        align-items: center;
        i {
          display: flex;
          line-height: 30px;
          color: red;
          overflow: hidden;
          &::before {
            font-size: 150px;
          }
        }
        span {
          color: red;
          font-weight: 600;
          margin-left: 8px;
          letter-spacing: 3px;
          font-size: 16px;
        }
      }
      .header-arrow {
        margin: 15px 5px;
        .arrow {
          margin: 0 5px;
          border-radius: 50%;
          cursor: pointer;
        }
        .arrow-left {
          position: relative;
          display: inline-block;
          width: 24px;
          height: 24px;
          background: rgba(0, 0, 0, 0.4);
          &:before {
            content: '';
            position: absolute;
            top: 50%;
            left: 60%;
            width: 8px;
            height: 8px;
            color: red;
            border-width: 0 0 1px 1px;
            border-color: transparent transparent #fff #fff;
            border-style: solid;
            transform: translate(-50%, -50%) rotate(45deg);
          }
        }
        .arrow-right {
          position: relative;
          display: inline-block;
          width: 24px;
          height: 24px;
          background: rgba(0, 0, 0, 0.4);
          .el-switch__label {
            font-size: 14px;
          }
          &:before {
            content: '';
            position: absolute;
            top: 50%;
            left: 40%;
            width: 8px;
            height: 8px;
            color: red;
            border-width: 0 1px 1px 0;
            border-color: transparent #fff #fff transparent;
            border-style: solid;
            transform: translate(-50%, -50%) rotate(-45deg);
          }
        }
      }
      .header-search {
        width: 284px;
        height: 32px;
        .el-input {
          height: 100%;
          /deep/ input {
            padding-left: 25px;
            height: 100%;
          }
          /deep/ .el-input__suffix {
            left: -259px;
            .el-input__icon {
              line-height: 32px;
            }
          }
        }
      }
    }
    .el-col-14 {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      font-size: 14px;
      .switch-group {
        .el-switch {
          margin: 0 5px;
        }
      }
      .login {
        margin: 0 20px;
        .login_a {
          display: flex;
          align-items: center;
          height: 100%;
        }
        .el-icon-user {
          margin-right: 5px;
        }
        img {
          width: 20px;
          height: 20px;
          border-radius: 50%;
          margin-right: 5px;
        }
      }
      .icon {
        a {
          margin: 5px;
          i {
            font-size: 27px;
            &::before {
              border-radius: 50%;
              overflow: hidden;
            }
            &:hover::before {
              background-color: orange;
            }
          }
        }
      }
    }
  }
}
.el-col-10 {
  height: 100%;
}
.el-col-14 {
  height: 100%;
}
/deep/.el-input__inner {
  border-radius: 20px;
}
/deep/.el-icon-search {
  margin-left: 10px;
}
</style>